package logic

import (
	"context"
	"newdoctor-management/models/mysql"

	"newdoctor-management/doctorroc/doctorroc"
	"newdoctor-management/doctorroc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type UpdateDoctorLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUpdateDoctorLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateDoctorLogic {
	return &UpdateDoctorLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *UpdateDoctorLogic) UpdateDoctor(in *doctorroc.UpdateDoctorRequest) (*doctorroc.UpdateDoctorResponse, error) {
	// todo: add your logic here and delete this line
	var doctor mysql.DoctorNew
	mysql.DB.Where("id = ?", in.Id).Find(&doctor)
	doctor = mysql.DoctorNew{
		Name:       in.Name,
		Ward:       in.Ward,
		Title:      in.Title,
		Department: in.Department,
		Product:    in.Product,
	}
	mysql.DB.Updates(&doctor)
	return &doctorroc.UpdateDoctorResponse{Id: int64(doctor.ID)}, nil
}
